package com.handong.handserialprogram.widget.component;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.handong.handserialprogram.R;
import com.handong.handserialprogram.widget.guideview.Component;


/**
 * Created by userKey on 2017/5/4.
 */

public class BottomComponent implements Component {

    public static Bitmap rotateBitmap(Bitmap paramBitmap, float paramFloat) {
        Matrix localMatrix = new Matrix();
        localMatrix.postRotate(paramFloat);
        return Bitmap.createBitmap(paramBitmap, 0, 0, paramBitmap.getWidth(), paramBitmap.getHeight(), localMatrix, true);
    }

    public int getAnchor() {
        return Component.ANCHOR_TOP;
    }

    public int getFitPosition() {
        return 32;
    }

    @Override
    public View getView(LayoutInflater paramLayoutInflater) {
        Context context = paramLayoutInflater.getContext();
        LinearLayout localLinearLayout = new LinearLayout(context);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        localLinearLayout.setOrientation(LinearLayout.VERTICAL);
        localLinearLayout.setLayoutParams(params);
        ImageView imageView = new ImageView(context);
        LinearLayout.LayoutParams imageParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        imageParams.gravity = Gravity.CENTER_HORIZONTAL;
        imageView.setLayoutParams(imageParams);
        imageView.setImageBitmap(rotateBitmap(BitmapFactory.decodeResource((context).getResources(), 2130837590), 180.0F));

        LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        TextView content = new TextView(context);
        content.setText("已绑定脚环，可向指挥中心请求开始任务！");
        content.setTextColor(paramLayoutInflater.getContext().getResources().getColor(R.color.text_white));
        content.setTextSize(16.0F);
        content.setPadding(5, 0, 0, 5);
        content.setLayoutParams(textParams);
        localLinearLayout.addView(imageView);
        localLinearLayout.addView(content);
        return localLinearLayout;
    }

    public int getXOffset() {
        return 0;
    }

    public int getYOffset() {
        return 0;
    }

}
